<template>
  <div class="interfaces">
    <!-- 按钮 -->
    <div class="btns">
      <el-form size="small" inline style="text-align:center">
        <br>
        <el-form-item  label="名称" >
          <el-input v-model="param.name" placeholder="请输入内容">></el-input>
        </el-form-item>
        <el-form-item>
          <el-button size="small" type="primary" icon="el-icon-search" @click="loadinterfaces">搜索</el-button>
        </el-form-item>
      </el-form>
       <div style="text-align:right">
        <el-button size= "small" type="warning" round  @click="downloadHandler">导出</el-button>
        <el-button size="small"  type="success" round  @click="toAddHandler">新增</el-button>
      </div>
    </div>
    <!-- /按钮 -->
    <!-- {{interfaces}} -->
    <!-- 表格 -->
    <el-table size="small" :data="interfaces">
      <el-table-column type="index" :index="1" label="序号"></el-table-column>
      <el-table-column label="名称" prop="name" align="center"></el-table-column>
      <el-table-column label="状态" prop="status" align="center"></el-table-column>
      <el-table-column label="接口" prop="url" align="center"></el-table-column>
      <el-table-column label="限制时间" prop="limitTimes" align="center"></el-table-column>
      <el-table-column label="用户名" prop="userName" align="center"></el-table-column>
      <el-table-column label="模型Id" prop="moduleId" align="center"></el-table-column>
      <el-table-column label="操作" width="100" align="center">
             <template slot-scope="scope">
          <el-button type="primary"  size="mini" icon="el-icon-edit"  @click="editHandler(scope.row)">修改</el-button >
          <br>
          <br>
          <el-button type="danger" size="mini" icon="el-icon-delete-solid"  @click="deleteHandler(scope.row)">删除</el-button >
        </template>
      </el-table-column>
    </el-table>
    <!-- /表格 -->
  </div>
</template>
<script>
import {get,post,del} from '@/utils/request'
export default {
  // 页面数据
  data(){ 
    return {
      param:{},
     interfaces:[]
    }
  },
  methods:{
     downloadHandler(){
      window.location.href = "http://8.131.68.179:9999/interfaces/download?name="+this.param.name
    },
        // 修改事件处理函数
    editHandler(row){
      // 跳转到修改页面 （新增页面）
      // 携带当前行的数据
      this.$router.push({
        path:"/interface/create",    //跳转的路由（前端）
        query:row   // 携带参数
      })
    },
        deleteHandler(row) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let url = "http://8.131.68.179:9999/interfaces/deleteById";
        del(url, { id: row.id }).then((resp) => {
          this.$message({ type: "success", message: resp.message });
          this.loadinterfaces();
        });
      });
    },
    toAddHandler(){
      this.$router.push("/interface/create")
    },  
  loadinterfaces(){
  let url = "http://8.131.68.179:9999/interfaces/query"
  get(url,this.param).then(resp => {
        this.interfaces = resp.data;
      })
    }
},
  // 页面渲染的时候会调用的函数
  created(){
    this.loadinterfaces();
  },
}
</script>
<style scoped>
.el-form{
  background:rgb(10, 231, 220);
}
</style>